const API_BASE = 'https://tihaidengta.xyz';
// const API_BASE = 'http://172.20.10.14:8001';
  // const { checkLoginAndActivation } = require('../../utils/auth.js');
Page({data: {
  theme: '',
  bookList: []// 存储四本书的数组
},
  onShow() {
  const app = getApp();
  this.setData({
    theme: app.globalData.isDarkMode ? 'dark-mode' : '',
    loading:false

  });
   // 请求书籍数据
    this.fetchBookList();
},

fetchBookList() {
  const token = wx.getStorageSync('token') || '';
  wx.request({
    url: `${API_BASE}/eduservice/subjectBank/selectSubjectBank/1/4`,
    method: 'GET',
    header: {
      'content-type': 'application/json',
      'token': token // ✅ 传递 token 到请求头
    },
    success: (res) => {
      if (res.data.code === 20000) {
        this.setData({
          bookList: res.data.data.list
        });
      } else {
        wx.showToast({
          title: '获取题库失败',
          icon: 'none'
        });
      }
    },
    fail: (err) => {
      wx.showToast({
        title: '网络错误',
        icon: 'none'
      });
      console.error('请求失败', err);
    }
  });
},
  goToBookPage(e) {
    const bankId = e.currentTarget.dataset.bankid;
    const bankName = e.currentTarget.dataset.name;

    wx.navigateTo({
      url: `/subpackage/exam/exam/exam?bankId=${bankId}&bankName=${encodeURIComponent(bankName)}`
    });
  },
  // 页面分享功能
  onShareAppMessage(){},
  onShareTimeline(){}

});